package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.annotation.Target;

@RestController
@RequestMapping("/admin/order")
@Api(tags = "订单管理接口")
public class OrdersController {

    @Autowired
    OrdersService ordersService;

    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> orderPageQuery(OrdersPageQueryDTO dto) {
        PageResult page = ordersService.orderPageQuery(dto);
        return Result.success(page);
    }

    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<Orders> getById(@PathVariable Long id) {
        Orders orders = ordersService.getById(id);
        return Result.success(orders);
    }

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancelOrder(@RequestBody OrdersCancelDTO dto) {
        ordersService.cancelOrder(dto);
        return Result.success();
    }

    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> statisticsOrder() {
        OrderStatisticsVO orderStatisticsVO = ordersService.statisticsOrder();
        return Result.success(orderStatisticsVO);
    }

    @PutMapping("complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id){
        ordersService.complete(id);
        return Result.success();
    }
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        ordersService.rejection(dto);
        return Result.success();

    }

}
